package com.example.administrator.ttphonehelper.process;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;

import java.util.List;
import java.util.Map;

/**
 * Created by gc on 2016/4/15.
 */
public class DeviceAdapter extends BaseExpandableListAdapter {
    private List<String> mList;
    private Map<String,List<String>> mMap;
    private Context mContext;
    public DeviceAdapter(Context context,Map<String,List<String>> map,List<String> list){
        this.mContext = context;
        this.mMap = map;
        this.mList = list;
    }
    @Override
    public int getGroupCount() {
        return mMap.size();
    }

    @Override
    public int getChildrenCount(int groupPosition) {
        return mMap.get(mList.get(groupPosition)).size();
    }

    @Override
    public Object getGroup(int groupPosition) {
        return mList.get(groupPosition);
    }

    @Override
    public Object getChild(int groupPosition, int childPosition) {
        return mMap.get(mList.get(groupPosition)).get(childPosition);
    }

    @Override
    public long getGroupId(int groupPosition) {
        return groupPosition;
    }

    @Override
    public long getChildId(int groupPosition, int childPosition) {
        return childPosition;
    }

    @Override
    public boolean hasStableIds() {
        return false;
    }

    @Override
    public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
        TextView groupView = new TextView(mContext);
        groupView.setPadding(30, 10, 0, 0);
        groupView.setTextColor(Color.BLUE);
        groupView.setTextSize(20);
        //为group赋值
        groupView.setText(mList.get(groupPosition));
        return groupView;
    }

    @Override
    public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
        TextView childView = new TextView(mContext);
        childView.setPadding(30, 10, 0, 0);
        childView.setTextColor(Color.BLACK);
        childView.setTextSize(20);
        //为child赋值
        childView.setText(mMap.get(mList.get(groupPosition)).get(childPosition));
        return childView;
    }

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return true;
    }
}
